<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">jQuery.browser</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/properties/">内部属性</a> &gt; <a href="/category/properties/global-jquery-object-properties/">全局 jQuery 对象的属性</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/utilities/">工具类</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/deprecated/">弃用</a> &gt; <a href="/category/deprecated/deprecated-1.3/">1.3 版本弃用的 API</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/removed/">已删除的函数</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/jQuery.browser/" target="_blank">jQuery.browser</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<div class="toc">
<h4><span>Contents:</span></h4>
<ul class="toc-list">
<li><a href="#jQuery-browser1">jQuery.browser</a></li>
<li><a href="#jQuery-browser-version2">jQuery.browser.version</a></li>
</ul>
</div><article class="entry property" id="jQuery-browser1"><h2 class="section-title">
<span>jQuery.browser</span><span class="returns">返回: <a href="/Types/#PlainObject">PlainObject</a></span><span class="version-details">version deprecated: <a href="/category/version/1.3/">1.3</a>, removed: <a href="/category/version/1.9/">1.9</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述:  </strong>
			用来获取useragent的包含标志，读取自 navigator.userAgent。<strong>这个属性在jQuery 1.9已经被删除</strong>并且只能通过的jQuery.migrate插件使用。请尝试使用特征检测代替。<del>
<strong>我们不推荐使用这个属性，请尝试使用功能检测来代替（见jQuery.support）。
			  jQuery.browser在未来的版本中可能会转移到一个jQuery插件。</strong> </del></p>
<ul class="signatures"><li class="signature"><h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.0/">1.0</a></span>jQuery.browser</h4></li></ul>
<div class="longdesc" id="entry-longdesc">
<p><code>$.browser</code>属性允许我们检测哪一个Web浏览器正在访问网页，通过浏览器本身返回。它包含四个最流行的浏览器类（在Internet Explorer，Mozilla和Webkit，和Opera）以及每个版本信息标志。</p>
<p>可用的标志有：</p>
<ul>
<li>webkit (从jQuery 1.4开始)</li>
<li>safari (不建议使用)</li>
<li>opera</li>
<li>msie</li>
<li>mozilla</li>
</ul>
<p>此属性是即刻有效的。因此，安全地使用它来判断是否要调用<code>$(document).ready()</code>。从jQuery 1.3开始，<code>$.browser</code>属性是不建议使用的，但目前还没有计划立即将其删除。</p>
<p>因为<code>$.browser</code>使用<code>navigator.userAgent</code>来确定平台，因为用户可以通过技术手段来修改该值，从而欺骗浏览器。避免该问题的最好办法就是使用<code>$.support</code>，<code>$.support</code>属性比<code>$.browser</code>提供更有效的检测特定功能的支持。</p>
</div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4>Example: <span class="desc">显示浏览器信息。</span>
</h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
<div class="line n17">17</div>
<div class="line n18">18</div>
<div class="line n19">19</div>
<div class="line n20">20</div>
<div class="line n21">21</div>
<div class="line n22">22</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">style</span>&gt;</span><span class="css"></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">p</span> <span class="rules">{ <span class="rule"><span class="attribute">color</span>:<span class="value">green;</span></span> <span class="rule"><span class="attribute">font-weight</span>:<span class="value">bolder;</span></span> <span class="rule"><span class="attribute">margin</span>:<span class="value"><span class="number">3</span>px <span class="number">0</span> <span class="number">0</span> <span class="number">10</span>px;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">div</span> <span class="rules">{ <span class="rule"><span class="attribute">color</span>:<span class="value">blue;</span></span> <span class="rule"><span class="attribute">margin-left</span>:<span class="value"><span class="number">20</span>px;</span></span> <span class="rule"><span class="attribute">font-size</span>:<span class="value"><span class="number">14</span>px;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">span</span> <span class="rules">{ <span class="rule"><span class="attribute">color</span>:<span class="value">red;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;/<span class="title">style</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">p</span>&gt;</span>Browser info:<span class="tag">&lt;/<span class="title">p</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript"></span></code></div></div><div class="container"><div class="line"><code>    jQuery.each(jQuery.browser, <span class="keyword">function</span>(i, val) {</code></div></div><div class="container"><div class="line"><code>      $(<span class="string">"&lt;div&gt;"</span> + i + <span class="string">" : &lt;span&gt;"</span> + val + <span class="string">"&lt;/span&gt;"</span>)</code></div></div><div class="container"><div class="line"><code>                .appendTo( document.body );</code></div></div><div class="container"><div class="line"><code>    });<span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div>
<div class="entry-example" id="example-1">
<h4>Example: <span class="desc">如果当前使用的浏览器是 Microsoft 的 Internet Explorer，那么下面的语句会返回 true。</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>  $.browser.msie;</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-2">
<h4>Example: <span class="desc">若使用的是 WebKit 的浏览器，则弹出提示框 "this is WebKit!"。
			
			</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>  <span class="keyword">if</span> ($.browser.webkit) {</code></div></div><div class="container"><div class="line"><code>    alert( <span class="string">"this is webkit!"</span> );</code></div></div><div class="container"><div class="line"><code>  }</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-3">
<h4>Example: <span class="desc">如果使用的是 Firefox 3，则弹出提示框 "Do stuff for Firefox 3"。</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code>  <span class="keyword">var</span> ua = $.browser;</code></div></div><div class="container"><div class="line"><code>  <span class="keyword">if</span> ( ua.mozilla &amp;&amp; ua.version.slice(<span class="number">0</span>,<span class="number">3</span>) == <span class="string">"1.9"</span> ) {</code></div></div><div class="container"><div class="line"><code>    alert( <span class="string">"Do stuff for firefox 3"</span> );</code></div></div><div class="container"><div class="line"><code>  }</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-4">
<h4>Example: <span class="desc">为不同的浏览器设置不同的 CSS 属性。</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code> <span class="keyword">if</span> ( $.browser.msie ) {</code></div></div><div class="container"><div class="line"><code>    $(<span class="string">"#div ul li"</span>).css( <span class="string">"display"</span>,<span class="string">"inline"</span> );</code></div></div><div class="container"><div class="line"><code> } <span class="keyword">else</span> {</code></div></div><div class="container"><div class="line"><code>    $(<span class="string">"#div ul li"</span>).css( <span class="string">"display"</span>,<span class="string">"inline-table"</span> );</code></div></div><div class="container"><div class="line"><code> }</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article><article class="entry property" id="jQuery-browser-version2"><h2 class="section-title">
<span>jQuery.browser.version</span><span class="returns">返回: <a href="/Types/#String">String</a></span><span class="version-details">version deprecated: <a href="/category/version/1.3/">1.3</a>, removed: <a href="/category/version/1.9/">1.9</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong>用户的浏览器渲染引擎的版本号。</p>
<ul class="signatures"><li class="signature"><h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.1.3/">1.1.3</a></span>jQuery.browser.version</h4></li></ul>
<div class="longdesc" id="entry-longdesc-1">
<p>以下是一些典型的结果：</p>
<ul>
<li>Internet Explorer: 6.0, 7.0, 8.0</li>
<li>Mozilla/Firefox/Flock/Camino: 1.7.12, 1.8.1.3, 1.9</li>
<li>Opera: 10.06, 11.01</li>
<li>Safari/Webkit: 312.8, 418.9</li>
</ul>
<p>请注意，IE8兼容性视要求成为ie 7。</p>
</div>
<section class="entry-examples" id="entry-examples-1"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-1-0">
<h4>Example: <span class="desc">Returns the version number of the rendering engine used by the user's current browser. For example, FireFox 4 returns 2.0 (the version of the Gecko rendering engine it utilizes).</span>
</h4>
<div class="syntaxhighlighter xml ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
<div class="line n10">10</div>
<div class="line n11">11</div>
<div class="line n12">12</div>
<div class="line n13">13</div>
<div class="line n14">14</div>
<div class="line n15">15</div>
<div class="line n16">16</div>
<div class="line n17">17</div>
<div class="line n18">18</div>
<div class="line n19">19</div>
<div class="line n20">20</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="doctype">&lt;!DOCTYPE html&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">html</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">style</span>&gt;</span><span class="css"></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">p</span> <span class="rules">{ <span class="rule"><span class="attribute">color</span>:<span class="value">blue;</span></span> <span class="rule"><span class="attribute">margin</span>:<span class="value"><span class="number">20</span>px;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">span</span> <span class="rules">{ <span class="rule"><span class="attribute">color</span>:<span class="value">red;</span></span> <span class="rule">}</span></span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;/<span class="title">style</span>&gt;</span></code></div></div><div class="container"><div class="line"><code>  <span class="tag">&lt;<span class="title">script</span> <span class="attribute">src</span>=<span class="value">"https://code.jquery.com/jquery-latest.js"</span>&gt;</span><span class="javascript"></span><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">head</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">p</span>&gt;</span><span class="tag">&lt;/<span class="title">p</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;<span class="title">script</span>&gt;</span><span class="javascript"></span></code></div></div><div class="container"><div class="line"><code>$(<span class="string">"p"</span>).html( <span class="string">"The version number of the rendering engine your browser uses is: &lt;span&gt;"</span> +</code></div></div><div class="container"><div class="line"><code>                $.browser.version + <span class="string">"&lt;/span&gt;"</span> );</code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">script</span>&gt;</span></code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">body</span>&gt;</span></code></div></div><div class="container"><div class="line"><code><span class="tag">&lt;/<span class="title">html</span>&gt;</span></code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
<h4>Demo:</h4>
<div class="demo code-demo"></div>
</div>
<div class="entry-example" id="example-1-1">
<h4>Example: <span class="desc">Alerts the version of IE's rendering engine that is being used:</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="keyword">if</span> ( $.browser.msie ) {</code></div></div><div class="container"><div class="line"><code>  alert( $.browser.version );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-1-2">
<h4>Example: <span class="desc">Often you only care about the "major number," the whole number, which you can get by using JavaScript's built-in <code>parseInt()</code> function:</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="keyword">if</span> ( $.browser.msie ) {</code></div></div><div class="container"><div class="line"><code>  alert( parseInt($.browser.version, <span class="number">10</span>) );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article> </div>
</article>